package com.rsk.utils.tools;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @description: 分页工具类
 */
public class PageUtils<T> implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** 当前页数 **/
    private int pageNumber;
    /** 总页数 **/
    private int pageTotal;
    /** 每页条数 **/
    private int pageSize;
    /** 总条数 **/
    private long dataTotal;
    /** 忽略数据条数 **/
    private int offset;

    /** 列表数据 **/
    private List<T> list = new ArrayList<T>();

    public PageUtils() {
    }

    public PageUtils(int pageNumber, int pageSize) {
        if (pageSize >= 1 && pageSize >= 1) {
            this.pageNumber = pageNumber;
            this.pageSize = pageSize;
        } else {
            throw new RuntimeException("invalid pageNumber: " + pageNumber + " or pageSize: " + pageSize);
        }
    }

    @SuppressWarnings("rawtypes")
	public static PageUtils create(int pageNumber, int pageSize) {
        return new PageUtils(pageNumber, pageSize);
    }

    public void setDataTotal(long dataTotal) {
        this.dataTotal = dataTotal;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getPageNumber() {
        return pageNumber == 0 ? 1 : pageNumber;
    }

    public int getPageTotal() {
        return Double.valueOf(Math.ceil((double) dataTotal / (double) pageSize)).intValue();
    }
    
    public int getOffset() {
        return pageSize * (getPageNumber() - 1);
    }

    public long getDataTotal() {
        return dataTotal;
    }

    public List<T> getList() {
        return list;
    }


}
